﻿#include "ZumaTaurus.h"
#include "../../../Shared/Enums.h"
#include "../../../Shared/Data/Stat.h"
#include "../../../Shared/Functions/Functions.h"
#include "../../../Shared/ServerPackets.h"
#include "../DelayedAction.h"
#include "../MonsterObject.h"
#include "../../Settings.h"

using namespace Server::MirDatabase;
namespace S = ServerPackets;

namespace Server::MirObjects::Monsters
{

    ZumaTaurus::ZumaTaurus(MonsterInfo *info) : ZumaMonster(info)
    {
        setDirection(MirDirection::DownLeft);
        AvoidFireWall = false;
    }

    void ZumaTaurus::ProcessAI()
    {
        if (Dead)
        {
            return;
        }

        if (Stats[Stat::HP] >= 7)
        {
            unsigned char stage = static_cast<unsigned char>(HP / (Stats[Stat::HP] / 7));

            if (stage < _stage)
            {
                SpawnSlaves();
            }
            _stage = stage;
        }


        ZumaMonster::ProcessAI();
    }

    void ZumaTaurus::Attack()
    {
        if (!getTarget()->IsAttackTarget(this))
        {
            setTarget(nullptr);
            return;
        }

        ShockTime = 0;

        setDirection(Functions::DirectionFromPoint(getCurrentLocation(), getTarget()->getCurrentLocation()));
        S::ObjectAttack *tempVar = new S::ObjectAttack();
        tempVar->ObjectID = ObjectID;
        tempVar->Direction = getDirection();
        tempVar->Location = getCurrentLocation();
        Broadcast(tempVar);

        ActionTime = getEnvir()->getTime() + 300;
        AttackTime = getEnvir()->getTime() + AttackSpeed;

        int damage = GetAttackPower(Stats[Stat::MinDC], Stats[Stat::MaxDC]);
        if (damage == 0)
        {
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
            return;
        }

        DelayedAction *action = new DelayedAction(DelayedType::Damage, getEnvir()->getTime() + 300, {getTarget(), damage, DefenceType::MACAgility});
        ActionList.push_back(action);

//C# TO C++ CONVERTER TODO TASK: A 'delete action' statement was not added since action was passed to a method or constructor. Handle memory management manually.
//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
    }

    void ZumaTaurus::SpawnSlaves()
    {
        int count = std::min(8, 40 - SlaveList.size());

        for (int i = 0; i < count; i++)
        {
            MonsterObject *mob = nullptr;
            switch (getEnvir()->Random->Next(7))
            {
                case 0:
                    mob = GetMonster(getEnvir()->GetMonsterInfo(Settings::Zuma1));
                    break;
                case 1:
                    mob = GetMonster(getEnvir()->GetMonsterInfo(Settings::Zuma2));
                    break;
                case 2:
                    mob = GetMonster(getEnvir()->GetMonsterInfo(Settings::Zuma3));
                    break;
                case 3:
                    mob = GetMonster(getEnvir()->GetMonsterInfo(Settings::Zuma4));
                    break;
                case 4:
                    mob = GetMonster(getEnvir()->GetMonsterInfo(Settings::Zuma5));
                    break;
                case 5:
                    mob = GetMonster(getEnvir()->GetMonsterInfo(Settings::Zuma6));
                    break;
                case 6:
                    mob = GetMonster(getEnvir()->GetMonsterInfo(Settings::Zuma7));
                    break;
            }

            if (mob == nullptr)
            {
                continue;
            }

            if (!mob->Spawn(getCurrentMap(), getFront()))
            {
                mob->Spawn(getCurrentMap(), getCurrentLocation());
            }

            mob->setTarget(getTarget());
            mob->ActionTime = getEnvir()->getTime() + 2000;
            SlaveList.push_back(mob);
        }
    }
}
